<?php

namespace app\api\controller\user;

use think\Controller;
use think\Request;

class Record extends Controller
{
    public function __construct()
    {
        parent::__construct();

        $this->RecordModel = model('common/User/Record');
        $this->UserModel = model('common/User/User');
    }

    public function index()
    {

        if ($this->request->isPost()) {

            $userid = $this->request->param('userid', 0);
            $state = $this->request->param('state', '');

            $user = $this->UserModel->find($userid);

            if (!$user) {
                $this->error('用户不存在');
                exit;
            }

            $where = [
                'userid' => $userid
            ];

            if (!empty($state)) {
                $where['state'] = $state;
            }

            $Record = $this->RecordModel->where($where)->select();

            if (!$Record) {
                $this->error('未找到消费记录');
                exit;
            } else {
                $this->success('返回消费记录成功', null, $Record);
                exit;
            }
        }
    }
}
